const config = require('../../../config').sms

const TopClient = require('./topClient').TopClient

const client = new TopClient(config)

module.exports = (phone) => {
  let code = (String(Math.ceil(Math.random() * 1000000000))).substr(-6, 6)
  let smsParam = {
    code: code,
    product: '纽诺育儿'
  }
  return new Promise((resolve, reject) => {
    client.execute('alibaba.aliqin.fc.sms.num.send', {
      'extend': '',
      'sms_type': 'normal',
      'sms_free_sign_name': '纽诺育儿',
      'sms_param': JSON.stringify(smsParam),
      'rec_num': `${phone}`,
      'sms_template_code': 'SMS_13051802'
    }, (error, response) => {
      if (!error) resolve(code)
      else reject(error)
    })
  })
}
